<?php 
	header('Content-type: application/rss+xml');
	print '<?xml version="1.0" encoding="utf-8"?>';
	

	require_once('config.php');
	$blogRoot="../".$blogRoot;

	require_once($blogRoot.'functions.php');

	$uri=explode('/',$_SERVER['REQUEST_URI']);

	$filename=$uri[sizeof($uri)-1];
	$args=explode('.',$filename);
		
	$userid=$args[0];

	//$feedlink=$_SERVER['REQUEST_URI'];
	$feedlink="http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
	// strip puddle part
	$feedlink=substr($feedlink,0,strpos($feedlink,"/puddle"));
	
	//2008-09-11T00:22:54.894+02:00
?>


<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">

<channel>
	<title><?=$blogname;?></title>
	<link><?=$feedlink; ?></link>
	<description><?=$blogtitle;?></description>
	<pubDate><?=date("r", time());?></pubDate>
	<atom:link rel="self" href="<?="http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];?>"/>
	<generator>Puddle Blog</generator>
	<docs>http://www.rssboard.org/rss-specification</docs>
	<?
		if ($profileimg) {
	?>
		<image>
			<url><?=$profileimg;?></url>
			<title><?=$blogname;?></title>
			<link><?=$feedlink;?></link>
		</image>
	<?
		}
	?>



<?
		$pagey=date("Y",time());
		$pagem=date("m",time());
		
		$pageCount=1;
		$postCount=0;
		
		$myfile=$blogRoot."txts/".$pagey.".".$pagem.".txt";

		
		$fileNotFound=0;

		while ($postCount<25) {
			
			// file exists and have zero size?
			if((file_exists($myfile)) && filesize($myfile)!="0") {
				// load archive
				$load = @file($myfile);
		
				// load lines
				while(count($load)>0 && $postCount<25) {
					$line=array_shift($load);
					
					$entry=explode("|",$line);
					
					// get timestamp, for link to the item
					$date = substr($entry[0],0,10);
					$date = explode(".",$date);
					$time= substr($entry[0],11,8);
					// explode time for unixtime
					$time = explode(":",$time);
					// create unixtime
					$unixtime = mktime($time[0], $time[1], $time[2], $date[1], $date[0], $date[2]);
					

					?>
					<item>
						<title><?=call_user_func($entry[2]."_getCaption",$line); ?></title>
						<link><?=$feedlink."?cmt=".$unixtime; ?></link>
						<guid><?=$feedlink."?cmt=".$unixtime;?></guid>
						<description><![CDATA[<?=call_user_func($entry[2]."_getPost",$line);?>]]></description>
						<pubDate><?=date("r", strtotime($entry[0]));?></pubDate>
					</item>
					<?

					$postCount++;
				}

			} else {
				$fileNotFound++;
				if ($fileNotFound>5) break;
			}
		}

?>
	</channel>
</rss>

